# coding:utf-8
import os

import numpy as np
import cv2
import matplotlib.pyplot as plt
graydir = r'F:\Resources\color\gray2'
# graydir = r'F:\Resources\color\gold'
for ii in os.listdir(graydir):
    image = os.path.join(graydir,ii)

    img = cv2.imread(image)
    print(img)
    # img = cv2.cvtColor(img,cv2.COLOR_RGB2HSV)
    print('img',img)
    # hist = cv2.calcHist(img,[0],None,[256],[0,256])
    # plt.plot(hist, color='r')
    # plt.show()
    color = ('h', 's', 'v')
    color = ('b','g','r')
    for i, col in enumerate(color):
        val = 180 if col == 'h' else 256
        histr:np.ndarray = cv2.calcHist([img], [i], None, [256], [0, 100])
        t = []
        # for i in histr:
        #     if i[0] <= 150:
        #         t.append(i)
        # histr = np.array(t)
        plt.plot(histr, color=col)
        plt.xlim([0, 256])
    # plt.savefig(fr'F:\Resources\color\goldHist\{ii}')
    plt.show()
    break
    # hist = cv2.calcHist(img,[0],None,[256],[0,256])
    # hist = np.histogram(img,bins=[0,255,0,255,0,255],range=255)
    # print(hist)
    cv2.imshow(ii,img)
cv2.waitKey(0)
cv2.destroyWindow()
